4 import java.awt.Rectangle;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.rmi.Naming;
8 import java.rmi.RemoteException;
9 import java.util.Enumeration;
10 import java.util.Vector;
12 import javax.swing.JButton;
13 import javax.swing.JFrame;
14 import javax.swing.JLabel;
15 import javax.swing.JPanel;
16 import javax.swing.JScrollPane;
17 import javax.swing.JTable;
18 import javax.swing.border.EmptyBorder;
19 import javax.swing.table.DefaultTableModel;
21 import common.AdminInterface;
22 import common.HouseInterface;
24 import configuration.___IntNames;
25 import domain.RuralHouse;
27 public class listOfAdditionRequestsGUI extends JFrame {
32 private static final long serialVersionUID = 1L;
33 private JPanel contentPane;
35 private DefaultTableModel tableModel;
36 private AdminInterface am = null;
37 private Vector<RuralHouse> houses;
41 public listOfAdditionRequestsGUI() {
44 am = (AdminInterface) Naming
45 .lookup(___IntNames.AdminManager);
46 } catch (Exception e1) {
47 System.out.println("Error accessing remote authentication: "
51 setTitle("Adding requests");
53 this.houses= am.getAdditionRequests();
55 } catch (Exception e) {
60 private void init() throws Exception {
61 setBounds(100, 100, 600, 450);
62 contentPane = new JPanel();
63 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
64 setContentPane(contentPane);
65 contentPane.setLayout(null);
67 JLabel lblNewLabel = new JLabel();
68 lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 27));
69 lblNewLabel.setBounds(23, 41, 536, 33);
70 contentPane.add(lblNewLabel);
72 lblNewLabel.setText("There are not houses to be added");
74 lblNewLabel.setText("List of houses to be added:");
75 JScrollPane scrollPane = new JScrollPane();
76 scrollPane.setBounds(new Rectangle(45, 305, 320, 116));
77 scrollPane.setBounds(23, 113, 536, 271);
78 contentPane.add(scrollPane);
80 table = new JTable() {
81 private static final long serialVersionUID = 1L;
83 public boolean isCellEditable(int row, int column) {
87 scrollPane.setViewportView(table);
88 tableModel = new DefaultTableModel(null, new String[] {
89 "House Name", "Bedrooms", "Kitchens", "Baths", "Parkings",
92 //Maybe there is a better way to avoid interaction.
93 //table.setEnabled(false);
94 table.setModel(tableModel);
96 JButton btnNewButton = new JButton("Confirm Addition");
97 btnNewButton.addActionListener(new ActionListener() {
98 public void actionPerformed(ActionEvent e) {
99 if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
100 HouseInterface hm= null;
102 hm = (HouseInterface) Naming
103 .lookup(___IntNames.HouseManager);
104 } catch (Exception e1) {
105 System.out.println("Error accessing remote authentication: "
109 RuralHouse rh = houses.get(table.getSelectedRow());
110 //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
112 hm.registerNewHouse(rh);
113 am.removeHouseAdditionRequests(rh);
115 } catch (RemoteException e1) {
116 // TODO Auto-generated catch block
117 e1.printStackTrace();
120 ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
125 btnNewButton.setBounds(88, 396, 169, 25);
126 contentPane.add(btnNewButton);
128 JButton btnDenyAddition = new JButton("Deny Addition");
129 btnDenyAddition.addActionListener(new ActionListener() {
130 public void actionPerformed(ActionEvent arg0) {
131 if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
132 RuralHouse rh = houses.get(table.getSelectedRow());
134 am.removeHouseAdditionRequests(rh);
136 } catch (RemoteException e) {
137 // TODO Auto-generated catch block
140 ((DefaultTableModel)table.getModel()).removeRow(houses.indexOf(rh));
145 btnDenyAddition.setBounds(300, 396, 169, 25);
146 contentPane.add(btnDenyAddition);
147 Enumeration<RuralHouse> en = houses.elements();
150 while (en.hasMoreElements()) {
151 rh = en.nextElement();
152 Vector<Object> row = new Vector<Object>();
153 row.add(rh.getHouseName());
154 row.add(rh.getFeatures().getnRooms());
155 row.add(rh.getFeatures().getnKitchens());
156 row.add(rh.getFeatures().getnBaths());
157 row.add(rh.getFeatures().getnParkings());
158 row.add(rh.getFeatures().getnLivings());
159 tableModel.addRow(row);